$.validator.setDefaults({
	submitHandler : function(form) {
		var id = $("#id").val();
		var url = "saveAction.html";
		var returnUrl = "list.html";
		if (id) {
			url = "../" + url;
			returnUrl = "../" + returnUrl;
		}
		var entity = {
			id : id,
			positionType : $("#positionType").val(),
			positionName : $("#positionName").val(),
			locationCity : $("#locationCity").val(),
			workExperience : $("#workExperience").val(),
			codingExperience : $("#codingExperience").val(),
			minEducation : $("#minEducation").val(),
			hireNum : $("#hireNum").val(),
			salaryRange : $("#salaryRange").val(),
			positionDescribe : $("#positionDescribe").val(),
			positionRequirement : $("#positionRequirement").val()
		};
		var onloadFunc = function(result) {
			if (result.isSuccess == true) {
				window.location = returnUrl;
			} else {
				alert(result.message);
			}
		};

		httpRequestPostJson(url, entity, true, onloadFunc);
	}

});
var validator = $("#myForm").validate({
	success : function(label) {
		label.addClass('ok');
	},
	rules : {
		positionName : {
			required : true,
			rangelength : [ 2, 30 ]
		},
		hireNum : {
			required : true
		},
		positionDescribe : {
			required : true
		},
		positionRequirement : {
			required : true
		}

	},
	messages : {
		positionName : {
			required : "请输入岗位名称",
			rangelength : "岗位名称2-30位"
		},
		hireNum : {
			required : "请输入招聘人数"
		},
		positionDescribe : {
			required : "请输入岗位描述"
		},
		positionRequirement : {
			required : "请输入岗位要求"
		}
	}
});

$("#reset").click(function() {
	$("#error").html('');
	validator.resetForm();
});

function del(id) {
	var url = 'deleteAction.html';
	var entity = {
		id : $('#id').val()
	};
	var onloadFunc = function(result) {
		if (result.isSuccess === true) {
			history.go(0);
		} else {
			alert(result.message);
		}
	}
	httpRequestPostJson(url, entity, false, onloadFunc);
}

function review(id) {
	window.location = 'detail/' + id + '.html';
}

function modify(id) {
	window.location = 'modify/' + id + '.html';
}